import {
    BrowserWindow,
} from 'electron';
import * as path from 'path';

export class MainWindow {
    win: BrowserWindow;
    constructor(opt: MainWindowOptions) {
        let width = 1664;
        let height = 928;
        this.win = new BrowserWindow({
            show: false,
            width: width,
            height: height,
            minWidth: width,
            minHeight: height,
            center: true,
            resizable: false,
            title: "coeus designer",
            skipTaskbar: false,
            // frame: true,
            autoHideMenuBar: true,
            webPreferences: {
                plugins: true,
                webSecurity: false,
                nodeIntegration: true,
                contextIsolation: false,
                allowRunningInsecureContent: true,
                defaultFontFamily: {
                    standard: `-apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', Helvetica, Arial, 'Hiragino Sans GB',
                    'Heiti SC', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif;`
                }
            },
            // icon: path.join(__dirname, 'assets/images/favicon.png')
        })
        this.win.once('ready-to-show', () => {
            this.win.show();
            opt.readyToShowHandle();
            if (process.env.NODE_ENV == 'dev') {
                this.openDevTools();
            }
        });
        this.win.on('close', opt.closeHandle.bind(this));

        // this.win.loadFile('./www/index.html');
        this.win.loadURL("http://ai.coeusbox.com");
        // this.win.loadURL("http://localhost:5173")
    }

    openDevTools() {
        (<any>this.win).openDevTools();
    }

    close() {
        this.win.close();
    }
}
export interface MainWindowOptions {
    closeHandle: () => void;
    readyToShowHandle: () => void;
}